var { group } = require("../../utils/api").default;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    list1: Array<object>([]),
    list2: Array<object>([]),
    list3: Array<object>([]),
  },
  onReady: async function () {
    const res = await group({
      method: 'post'
    })
    let list = res.data.data.list;
    let list1: Array<object> = [], list2: Array<object> = [], list3: Array<object> = [];
    list.forEach((e: any) => {
      if (e.state == 1) {
        list1.push(e)
      } else if (e.state == 2) {
        list2.push(e)
      } else {
        list3.push(e)
      }
    });
    this.setData({
      list1: list1,
      list2: list2,
      list3: list3,
    })
  },
  //swiper切换时会调用
  pagechange: function (e: any) {
    if ("touch" === e.detail.source) {
      let currentPageIndex = this.data.currentIndex
      currentPageIndex = (currentPageIndex + 1) % 3
      this.setData({
        currentIndex: currentPageIndex
      })
    }
  },
  //用户点击tab时调用
  titleClick: function (e: any) {
    this.setData({
      //拿到当前索引并动态改变
      currentIndex: e.currentTarget.dataset.idx
    })
  }
})